package com.flannery.learningandroid.data.kotlin

fun main(args: Array<String>) {
    testWhile()
}


fun testFor() {
    var items = arrayOf(1, 2, 3, 4, 5, 6, 7)
    for (item in items) {
        print(item)
    }
    for (index in items.indices) {
        print(items[index])
    }
}

fun testWhile() {
    var x = 5
    while (x > 0) {
        print(x--)
    }
    println()
    x = 5
    do {
        print(x--)
    } while (x > 0)
}


fun testIF() {
    var value = 3
    var c = if (value != 3) value else "Other"
    println(c)

    if (value in 1..8) println("is in 1..8")
}


fun testWhen() {
    val value = 3
    when (value) {
        1 -> println("x==1")
        2 -> println("x==2")
        3, 4 -> println("x==3 or x==4")
        in 5..7 -> println("in 5..7")
        !in 10..20 -> println()
        is Int -> println() //value已经确定Int，所以可以这样判断
        else -> {
            println("x不是1，也不是2")
        }
    }
}